package com.leyou.web.mq;

import com.leyou.common.constants.MQConstants;
import com.leyou.web.service.IPageService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 处理请求和响应的方法
 *
 * @version V1.0
 * @package com.leyou.search.mq
 * @description:
 * @author: pc
 * @date: 2019/7/5 21:46
 */
@Component
public class ItemListener {
    @Autowired
    private IPageService pageService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.Queue.PAGE_ITEM_UP,durable = "true"),
            exchange = @Exchange(name = MQConstants.Exchange.ITEM_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKey.ITEM_UP_KEY
    ))
    public void listenerInsert(Long spuId) {
        if (spuId != null) {
            pageService.creatItemHtml(spuId);
        }
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.Queue.SEARCH_ITEM_DOWN,durable = "true"),
            exchange = @Exchange(name = MQConstants.Exchange.ITEM_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKey.ITEM_DOWN_KEY
    ))
    public void listenerDelete(Long spuId) {
        if (spuId != null) {
            pageService.deleteItemHtmL(spuId);
        }
    }
}
